<?php
function searhobject($params) {

	$db_prefix = elgg_get_config ( 'dbprefix' );

	$join = "JOIN {$db_prefix}objects_entity oe ON e.guid = oe.guid";
	$params ['joins'] = array (
			$join
	);
	$fields = array (
			'title',
			'description'
	);

	$where = search_get_where_sql ( 'oe', $fields, $params );

	$params ['wheres'] = array (
			$where
	);
	$params ['count'] = TRUE;
	$count = elgg_get_entities ( $params );

	// no need to continue if nothing here.
	if (! $count) {
		return array (
				'entities' => array (),
				'count' => $count
		);
	}

	$params ['count'] = FALSE;
	$params ['order_by'] = search_get_order_by_sql ( 'e', 'oe', $params ['sort'], $params ['order'] );
	$entities = elgg_get_entities ( $params );

	// add the volatile data for why these entities have been returned.
	foreach ( $entities as $entity ) {
		$title = search_get_highlighted_relevant_substrings ( $entity->title, $params ['query'] );
		$entity->setVolatileData ( 'search_matched_title', $title );

		$desc = search_get_highlighted_relevant_substrings ( $entity->description, $params ['query'] );
		$entity->setVolatileData ( 'search_matched_description', $desc );
	}

	return array (
			'entities' => $entities,
			'count' => $count
	);
}